/**
 * Copyright (C) 2009+ Spark Zheng
 *
 * @file        test/test_buffer.c 
 * @date        2010-04-05
 * @brief	
 * @see		dlib       
 * @history
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "buffer.h"

#define	SIZE	16
#define FIRST	"INIT_TEST;"
#define APPEND	"APPEND_TEST;"
#define PREPEND	"PREPEND_TEST;"
#define END	"END_TEST;"

int main(int argc, char **argv)
{
	UNUSED_PARAM(argc);
	UNUSED_PARAM(argv);
	fprintf(stderr, "sizeof INIT_TASK is %d.\n", sizeof("INIT_TASK"));
	fprintf(stderr, "strlen INIT_TASK is %d.\n", strlen("INIT_TASK"));
	dlib_buffer_t *buffer = dlib_buffer_init(SIZE);

	fprintf(stderr, "\nBuffer append %s.\n", FIRST);
	buffer = dlib_buffer_append(buffer, FIRST, strlen(FIRST));
	dlib_buffer_dump(buffer, NULL);

	fprintf(stderr, "\nBuffer append %s.\n", APPEND);
	buffer = dlib_buffer_append(buffer, APPEND, strlen(APPEND));
	dlib_buffer_dump(buffer, NULL);

	fprintf(stderr, "\nBuffer prepend %s.\n", PREPEND);
	buffer = dlib_buffer_prepend(buffer, PREPEND, strlen(PREPEND));
	dlib_buffer_dump(buffer, NULL);

	fprintf(stderr, "\nBuffer append %s.\n", END);
	buffer = dlib_buffer_append(buffer, END, strlen(END));
	dlib_buffer_dump(buffer, NULL);

	dlib_buffer_set_offset(buffer, buffer->buff_offset - strlen(END));

	fprintf(stderr, "\nBuffer prepend %s.\n", PREPEND);
	buffer = dlib_buffer_prepend(buffer, PREPEND, strlen(PREPEND));
	dlib_buffer_dump(buffer, NULL);

	fprintf(stderr, "\nBuffer append %s.\n", END);
	buffer = dlib_buffer_append(buffer, END, strlen(END));
	dlib_buffer_dump(buffer, NULL);

	dlib_buffer_exit(buffer);
	return 0;
}
